var c = !0;

module.exports = {
    downloadSaveImages: function(e) {
        function o(e) {
            var a = wx.downloadFile({
                url: s[e],
                success: function(c) {
                    var s = c.tempFilePath;
                    wx.saveImageToPhotosAlbum({
                        filePath: s,
                        success: function() {
                            t && (u && u(e), e < i - 1 ? o(e += 1) : t({
                                code: 1001,
                                msg: "保存成功"
                            }));
                        },
                        fail: function() {
                            n && n({
                                code: 1002,
                                msg: "保存失败"
                            });
                        }
                    });
                },
                fail: function(c) {
                    n && n({
                        code: 1003,
                        msg: "下载失败"
                    });
                }
            });
            c || a.abort();
        }
        var t = e.success, n = e.fail, s = e.urls, i = s.length, u = e.current;
        wx.getSetting({
            success: function(c) {
                c.authSetting["scope.writePhotosAlbum"] ? o(0) : wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        o(0);
                    },
                    fail: function() {
                        wx.showModal({
                            title: "授权失败",
                            content: "您还未授权，无法将图片保存到您的手机，是否重新设置授权？",
                            confirmText: "去授权",
                            cancelText: "拒绝",
                            success: function(c) {
                                c.confirm ? wx.openSetting() : c.cancel;
                            }
                        }), n && n({
                            code: 1004,
                            msg: "授权失败"
                        });
                    }
                });
            },
            fail: function(c) {
                n && n({
                    code: 1004,
                    msg: "授权失败"
                });
            }
        });
    },
    cancelDown: function() {
        c = !1;
    }
};